﻿//# 查看code.o的代码段
//$ objdump - d code.o
//code.o: file format elf64 - x86 - 64
//Disassembly of section.text :
//	0000000000000000 < run > :
//	0 : f3 0f 1e fa endbr64
//	4 : 55 push % rbp
//	5 : 48 89 e5 mov % rsp, % rbp
//	8 : 48 8d 3d 00 00 00 00 lea 0x0(% rip), % rdi # f
//	<run + 0xf>
//	f: e8 00 00 00 00 callq 14 < run + 0x14 >
//	14 : 90 nop
//	15 : 5d pop % rbp
//	16 : c3 retq
//	# 插看hello.o的代码段
//	$ objdump - d hello.o
//	hello.o: file format elf64 - x86 - 64
//	Disassembly of section.text :
//	0000000000000000 < main > :
//	0 : f3 0f 1e fa endbr64
//	4 : 55 push % rbp
//	5 : 48 89 e5 mov % rsp, % rbp
//	8 : 48 8d 3d 00 00 00 00 lea 0x0(% rip), % rdi # f
//	<main + 0xf>
//	f: e8 00 00 00 00 callq 14 < main + 0x14 >
//	14 : b8 00 00 00 00 mov $0x0, % eax
//	19 : e8 00 00 00 00 callq 1e <main + 0x1e>
//	1e : b8 00 00 00 00 mov $0x0, % eax
//	23 : 5d pop % rbp
//	24 : c3 retq
//	⾄此就是之前的结论：多个.o彼此不知道对⽅
//	# 读取code.o符合表
//	$ readelf - s code.o
//	Symbol table '.symtab' contains 13 entries:
//Num: Value Size Type Bind Vis Ndx Name
//0 : 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
//1 : 0000000000000000 0 FILE LOCAL DEFAULT ABS code.c
//2 : 0000000000000000 0 SECTION LOCAL DEFAULT 1
//3 : 0000000000000000 0 SECTION LOCAL DEFAULT 3
//4 : 0000000000000000 0 SECTION LOCAL DEFAULT 4
//5 : 0000000000000000 0 SECTION LOCAL DEFAULT 5
//6 : 0000000000000000 0 SECTION LOCAL DEFAULT 7
//7 : 0000000000000000 0 SECTION LOCAL DEFAULT 8
//8 : 0000000000000000 0 SECTION LOCAL DEFAULT 9
//9 : 0000000000000000 0 SECTION LOCAL DEFAULT 6
//10 : 0000000000000000 23 FUNC GLOBAL DEFAULT 1 run
//11 : 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND
//_GLOBAL_OFFSET_TABLE_
//12 : 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts
//puts：就是printf的实现
//UND就是：undefine，表⽰未定义说⽩了就是本.o⽂件找不到
//# 读取hello.o符合表
//whb@bite:~/ test / test / test$ readelf - s hello.o
//Symbol table '.symtab' contains 14 entries :
//	Num : Value Size Type Bind Vis Ndx Name
//	0 : 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
//	1 : 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c
//	2 : 0000000000000000 0 SECTION LOCAL DEFAULT 1
//	3 : 0000000000000000 0 SECTION LOCAL DEFAULT 3
//	4 : 0000000000000000 0 SECTION LOCAL DEFAULT 4
//	5 : 0000000000000000 0 SECTION LOCAL DEFAULT 5
//	6 : 0000000000000000 0 SECTION LOCAL DEFAULT 7
//	7 : 0000000000000000 0 SECTION LOCAL DEFAULT 8
//	8 : 0000000000000000 0 SECTION LOCAL DEFAULT 9
//	9 : 0000000000000000 0 SECTION LOCAL DEFAULT 6
//	10 : 0000000000000000 37 FUNC GLOBAL DEFAULT 1 main
//	11 : 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND
//	_GLOBAL_OFFSET_TABLE_
//	12 : 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND puts
//	13 : 0000000000000000 0 NOTYPE GLOBAL DEFAULT UND run
//	puts：就是printf的实现， run就是我们⾃⼰的⽅法在hello.o中未定义(因为在code.o中)
//	UND就是：undefine，表⽰未定义说⽩了就是本.o⽂件找不到
//	# 读取hello.o符合表
//	$ readelf - s main.exe
//	Symbol table '.dynsym' contains 7 entries:
//Num: Value Size Type Bind Vis Ndx Name
//0 : 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
//1 : 0000000000000000 0 NOTYPE WEAK DEFAULT UND
//_ITM_deregisterTMCloneTab
//2 : 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@GLIBC_2.2.5 (2)
//3: 0000000000000000 0 FUNC GLOBAL DEFAULT UND
//__libc_start_main@GLIBC_2.2.5 (2)
//4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
//5 : 0000000000000000 0 NOTYPE WEAK DEFAULT UND
//_ITM_registerTMCloneTable
//6 : 0000000000000000 0 FUNC WEAK DEFAULT UND
//__cxa_finalize@GLIBC_2.2.5 (2)
//Symbol table '.symtab' contains 67 entries:
//Num: Value Size Type Bind Vis Ndx Name
//0 : 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
//1 : 0000000000000318 0 SECTION LOCAL DEFAULT 1
//2: 0000000000000338 0 SECTION LOCAL DEFAULT 2
//3: 0000000000000358 0 SECTION LOCAL DEFAULT 3
//4: 000000000000037c 0 SECTION LOCAL DEFAULT 4
//5 : 00000000000003a0 0 SECTION LOCAL DEFAULT 5
//6 : 00000000000003c8 0 SECTION LOCAL DEFAULT 6
//7 : 0000000000000470 0 SECTION LOCAL DEFAULT 7
//8 : 00000000000004f2 0 SECTION LOCAL DEFAULT 8
//9 : 0000000000000500 0 SECTION LOCAL DEFAULT 9
//10 : 0000000000000520 0 SECTION LOCAL DEFAULT 10
//11 : 00000000000005e0 0 SECTION LOCAL DEFAULT 11
//12 : 0000000000001000 0 SECTION LOCAL DEFAULT 12
//13 : 0000000000001020 0 SECTION LOCAL DEFAULT 13
//14 : 0000000000001040 0 SECTION LOCAL DEFAULT 14
//15 : 0000000000001050 0 SECTION LOCAL DEFAULT 15
//16 : 0000000000001060 0 SECTION LOCAL DEFAULT 16
//17 : 0000000000001208 0 SECTION LOCAL DEFAULT 17
//18: 0000000000002000 0 SECTION LOCAL DEFAULT 18
//19 : 000000000000201c 0 SECTION LOCAL DEFAULT 19
//20 : 0000000000002068 0 SECTION LOCAL DEFAULT 20
//21: 0000000000003db8 0 SECTION LOCAL DEFAULT 21
//22 : 0000000000003dc0 0 SECTION LOCAL DEFAULT 22
//23 : 0000000000003dc8 0 SECTION LOCAL DEFAULT 23
//24 : 0000000000003fb8 0 SECTION LOCAL DEFAULT 24
//25 : 0000000000004000 0 SECTION LOCAL DEFAULT 25
//26 : 0000000000004010 0 SECTION LOCAL DEFAULT 26
//27 : 0000000000000000 0 SECTION LOCAL DEFAULT 27
//28 : 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
//29 : 0000000000001090 0 FUNC LOCAL DEFAULT 16 deregister_tm_clones
//30: 00000000000010c0 0 FUNC LOCAL DEFAULT 16 register_tm_clones
//31 : 0000000000001100 0 FUNC LOCAL DEFAULT 16
//__do_global_dtors_aux
//32 : 0000000000004010 1 OBJECT LOCAL DEFAULT 26 completed.8061
//33 : 0000000000003dc0 0 OBJECT LOCAL DEFAULT 22
//__do_global_dtors_aux_fin
//34 : 0000000000001140 0 FUNC LOCAL DEFAULT 16 frame_dummy
//35 : 0000000000003db8 0 OBJECT LOCAL DEFAULT 21
//__frame_dummy_init_array_
//36 : 0000000000000000 0 FILE LOCAL DEFAULT ABS code.c
//37 : 0000000000000000 0 FILE LOCAL DEFAULT ABS hello.c
//38 : 0000000000000000 0 FILE LOCAL DEFAULT ABS crtstuff.c
//39 : 000000000000218c 0 OBJECT LOCAL DEFAULT 20 __FRAME_END__
//40: 0000000000000000 0 FILE LOCAL DEFAULT ABS
//41 : 0000000000003dc0 0 NOTYPE LOCAL DEFAULT 21 __init_array_end
//42 : 0000000000003dc8 0 OBJECT LOCAL DEFAULT 23 _DYNAMIC
//43 : 0000000000003db8 0 NOTYPE LOCAL DEFAULT 21 __init_array_start
//44 : 000000000000201c 0 NOTYPE LOCAL DEFAULT 19 __GNU_EH_FRAME_HDR
//45 : 0000000000003fb8 0 OBJECT LOCAL DEFAULT 24
//_GLOBAL_OFFSET_TABLE_
//46 : 0000000000001000 0 FUNC LOCAL DEFAULT 12 _init
//47 : 0000000000001200 5 FUNC GLOBAL DEFAULT 16 __libc_csu_fini
//48 : 0000000000000000 0 NOTYPE WEAK DEFAULT UND
//_ITM_deregisterTMCloneTab
//49 : 0000000000004000 0 NOTYPE WEAK DEFAULT 25 data_start
//50 : 0000000000000000 0 FUNC GLOBAL DEFAULT UND puts@@GLIBC_2.2.5
//51: 0000000000004010 0 NOTYPE GLOBAL DEFAULT 25 _edata
//52 : 0000000000001149 23 FUNC GLOBAL DEFAULT 16 run
//53: 0000000000001208 0 FUNC GLOBAL HIDDEN 17 _fini
//54: 0000000000000000 0 FUNC GLOBAL DEFAULT UND
//__libc_start_main@@GLIBC_
//55: 0000000000004000 0 NOTYPE GLOBAL DEFAULT 25 __data_start
//56 : 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
//57 : 0000000000004008 0 OBJECT GLOBAL HIDDEN 25 __dso_handle
//58: 0000000000002000 4 OBJECT GLOBAL DEFAULT 18 _IO_stdin_used
//59 : 0000000000001190 101 FUNC GLOBAL DEFAULT 16 __libc_csu_init
//60: 0000000000004018 0 NOTYPE GLOBAL DEFAULT 26 _end
//61: 0000000000001060 47 FUNC GLOBAL DEFAULT 16 _start
//62 : 0000000000004010 0 NOTYPE GLOBAL DEFAULT 26 __bss_start
//63 : 0000000000001160 37 FUNC GLOBAL DEFAULT 16 main
//64 : 0000000000004010 0 OBJECT GLOBAL HIDDEN 25 __TMC_END__
//65 : 0000000000000000 0 NOTYPE WEAK DEFAULT UND
//_ITM_registerTMCloneTable
//66 : 0000000000000000 0 FUNC WEAK DEFAULT UND
//__cxa_finalize@@GLIBC_2.2
//两个.o进⾏合并之后，在最终的可执⾏程序中，就找到了run
//0000000000001149：其实是地址，后⾯说
//FUNC : 表⽰run符号类型是个函数
//16：就是run函数所在的section被合并最终的那⼀个section中了, 16就是下标
//# 读取可执⾏程序最终的所有的section清单
//$ readelf - S main.exe
//There are 31 section headers, starting at offset 0x39b0:
//Section Headers :
//[Nr] Name Type Address Offset
//Size EntSize Flags Link Info Align
//[0] NULL 0000000000000000 00000000
//0000000000000000 0000000000000000 0 0 0
//[1].interp PROGBITS 0000000000000318 00000318
//000000000000001c 0000000000000000 A 0 0 1
//[2].note.gnu.propert NOTE 0000000000000338 00000338
//0000000000000020 0000000000000000 A 0 0 8
//[3].note.gnu.build - i NOTE 0000000000000358 00000358
//0000000000000024 0000000000000000 A 0 0 4
//[4].note.ABI - tag NOTE 000000000000037c 0000037c
//0000000000000020 0000000000000000 A 0 0 4
//[5].gnu.hash GNU_HASH 00000000000003a0 000003a0
//0000000000000024 0000000000000000 A 6 0 8
//[6].dynsym DYNSYM 00000000000003c8 000003c8
//00000000000000a8 0000000000000018 A 7 1 8
//[7].dynstr STRTAB 0000000000000470 00000470
//0000000000000082 0000000000000000 A 0 0 1
//[8].gnu.version VERSYM 00000000000004f2 000004f2
//000000000000000e 0000000000000002 A 6 0 2
//[9].gnu.version_r VERNEED 0000000000000500 00000500
//0000000000000020 0000000000000000 A 7 1 8
//[10].rela.dyn RELA 0000000000000520 00000520
//00000000000000c0 0000000000000018 A 6 0 8
//[11].rela.plt RELA 00000000000005e0 000005e0
//0000000000000018 0000000000000018 AI 6 24 8
//[12].init PROGBITS 0000000000001000 00001000
//000000000000001b 0000000000000000 AX 0 0 4
//[13].plt PROGBITS 0000000000001020 00001020
//0000000000000020 0000000000000010 AX 0 0 16
//[14].plt.got PROGBITS 0000000000001040 00001040
//0000000000000010 0000000000000010 AX 0 0 16
//[15].plt.sec PROGBITS 0000000000001050 00001050
//0000000000000010 0000000000000010 AX 0 0 16
//[16].text PROGBITS 0000000000001060 00001060
//00000000000001a5 0000000000000000 AX 0 0 16
//[17].fini PROGBITS 0000000000001208 00001208
//000000000000000d 0000000000000000 AX 0 0 4
//[18].rodata PROGBITS 0000000000002000 00002000
//000000000000001c 0000000000000000 A 0 0 4
//[19].eh_frame_hdr PROGBITS 000000000000201c 0000201c
//000000000000004c 0000000000000000 A 0 0 4
//[20].eh_frame PROGBITS 0000000000002068 00002068
//0000000000000128 0000000000000000 A 0 0 8
//[21].init_array INIT_ARRAY 0000000000003db8 00002db8
//0000000000000008 0000000000000008 WA 0 0 8
//[22].fini_array FINI_ARRAY 0000000000003dc0 00002dc0
//0000000000000008 0000000000000008 WA 0 0 8
//[23].dynamic DYNAMIC 0000000000003dc8 00002dc8
//00000000000001f0 0000000000000010 WA 7 0 8
//[24].got PROGBITS 0000000000003fb8 00002fb8
//0000000000000048 0000000000000008 WA 0 0 8
//[25].data PROGBITS 0000000000004000 00003000
//0000000000000010 0000000000000000 WA 0 0 8
//[26].bss NOBITS 0000000000004010 00003010
//0000000000000008 0000000000000000 WA 0 0 1
//[27].comment PROGBITS 0000000000000000 00003010
//000000000000002b 0000000000000001 MS 0 0 1
//[28].symtab SYMTAB 0000000000000000 00003040
//0000000000000648 0000000000000018 29 47 8
//[29].strtab STRTAB 0000000000000000 00003688
//000000000000020e 0000000000000000 0 0 1
//[30].shstrtab STRTAB 0000000000000000 00003896
//000000000000011a 0000000000000000 0 0 1
//Key to Flags :
//W(write), A(alloc), X(execute), M(merge), S(strings), I(info),
//L(link order), O(extra OS processing required), G(group), T(TLS),
//C(compressed), x(unknown), o(OS specific), E(exclude),
//l(large), p(processor specific)